#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int findMaxForm(vector<string>& strs, int m, int n) {
        int si = strs.size();
        vector<pair<int, int>> pp(si);
        for (int i = 0; i < si; ++i) zeroNum(strs[i], i, pp);

        vector<vector<int>> dp(m + 1, vector<int>(n + 1));
        for (auto& e : pp)
        {
            for (int j = m; j >= e.first; --j)
            {
                for (int k = n; k >= e.second; --k)
                {
                    dp[j][k] = max(dp[j][k], dp[j - e.first][k - e.second] + 1);
                }
            }
        }

        return dp[m][n];
    }

    void zeroNum(string& tmp, int i, vector<pair<int, int>>& pp)
    {
        for (auto& e : tmp)
            if (e - '0') pp[i].second++;
            else    pp[i].first++;
    }
};